package wangjg.android.media.record;

import wangjg.android.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;

public class CaptureActivity extends Activity {
	private MediaCapture mc = new MediaCapture();
	MyMediaPlayer mp = new MyMediaPlayer();
	private SurfaceView previewSurface = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.camera_main);
		this.init();
	}

	private void init() {
		previewSurface = (SurfaceView) this.findViewById(R.id.preview_surface);
		SurfaceHolder holder = previewSurface.getHolder();
//		holder.addCallback(mc);
		holder.addCallback(mp);
		holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
		previewSurface.setVisibility(View.VISIBLE);

		final Button btn_record = (Button) this.findViewById(R.id.btn_record);
		btn_record.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(mc.isRecording()){
//					mc.stop();
					mp.stop();
					btn_record.setText("start");
				}else{
//					mc.start();
					mp.start();
					btn_record.setText("stop");
				}
			}
		});
	}

	@Override
	public void onPause() {
		super.onPause();
		mc.stop();
	}

}
